package vip.xiaonuo.smzq.modular.synchronize.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.synchronize.entity.TableFields;
import vip.xiaonuo.smzq.modular.synchronize.service.ITableFieldsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 表字段管理表
 *
 * @author sqq
 * @since 2025-02-21
 */
@Api(tags = "表字段管理表")
@RestController
@RequestMapping("/synchronize/tableFields")
@Validated
public class TableFieldsController {

    @Resource
    private ITableFieldsService iTableFieldsService;

    /**
     * 添加表字段管理表
     */
    @ApiOperation("添加表字段管理表")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid TableFields tableFields) {
        iTableFieldsService.save(tableFields);
        return CommonResult.ok();
    }

    /**
     * 删除表字段管理表
     */
    @ApiOperation("删除表字段管理表")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iTableFieldsService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑表字段管理表
     */
    @ApiOperation("编辑表字段管理表")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid TableFields tableFields) {
        iTableFieldsService.updateById(tableFields);
        return CommonResult.ok();
    }

    /**
     * 表字段管理表分页查询
     */
    @ApiOperation("表字段管理表分页查询")
    @GetMapping("/list")
    public CommonResult<Page<TableFields>> page() {
        return CommonResult.data(iTableFieldsService.page(new TableFields()));
    }
}
